package org.jeecg.modules.haili.utils;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * 投保工具类
 */
public class InsUtils {
    private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    private final static DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static String formatYdate(Date ydate) {
        ydate = new Date();
        Instant instant = ydate.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();

        // atZone()方法返回在指定时区从此Instant生成的ZonedDateTime。
        LocalDateTime localDate = instant.atZone(zoneId).toLocalDateTime();
        localDate = localDate.plusHours(2);
        String nDate = localDate.format(formatter);
//        System.out.println(nDate);
        return nDate;
    }

    public static String oneMonthLater(Date date) {
        LocalDateTime ydate = LocalDateTime.parse(formatYdate(date), df);
        LocalDateTime endDate = ydate.plusMonths(1);
        endDate.plusDays(1);
        endDate.minus(1, ChronoUnit.SECONDS);
        return endDate.format(formatter);
    }

    public static String dotRate(Double rate) {
        if (rate == null) {
            return "0";
        }
        BigDecimal rdecimal = new BigDecimal(rate);
        return String.format("%.5f", rdecimal.divide(new BigDecimal(10000)));
    }
}
